BundleCompat

Helper for accessing features in Bundle.

Functions

Link copied to clipboard
@Nullable
open fun getBinder(@NonNull bundle: @NonNull Bundle, @Nullable key: @Nullable String): @Nullable IBinder
A convenience method to handle getting an IBinder inside a Bundle for all Android versions.
Link copied to clipboard
open fun <T> getParcelable(@NonNull in: @NonNull Bundle, @Nullable key: @Nullable String, @NonNull clazz: @NonNull Class<T>): @Nullable T
Returns the value associated with the given key or null if:
  • No mapping of the desired type exists for the given key.
  • A null value is explicitly associated with the key.
  • The object is not of type clazz.
Note: if the expected value is not a class provided by the Android platform, you must call setClassLoader with the proper ClassLoader first.
Link copied to clipboard
open fun getParcelableArray(@NonNull in: @NonNull Bundle, @Nullable key: @Nullable String, @NonNull clazz: @NonNull Class<out Parcelable>): @Nullable Array<Parcelable>
Returns the value associated with the given key, or null if:
  • No mapping of the desired type exists for the given key.
  • A null value is explicitly associated with the key.
  • The object is not of type clazz.
Note: if the expected value is not a class provided by the Android platform, you must call setClassLoader with the proper ClassLoader first.
Link copied to clipboard
open fun <T> getParcelableArrayList(@NonNull in: @NonNull Bundle, @Nullable key: @Nullable String, @NonNull clazz: @NonNull Class<out T>): @Nullable ArrayList<T>
Returns the value associated with the given key, or null if:
  • No mapping of the desired type exists for the given key.
  • A null value is explicitly associated with the key.
  • The object is not of type clazz.
Note: if the expected value is not a class provided by the Android platform, you must call setClassLoader with the proper ClassLoader first.
Link copied to clipboard
open fun <T : Serializable?> getSerializable(@NonNull in: @NonNull Bundle, @Nullable key: @Nullable String, @NonNull clazz: @NonNull Class<T>): @Nullable T
Returns the value associated with the given key or null if:
  • No mapping of the desired type exists for the given key.
  • A null value is explicitly associated with the key.
  • The object is not of type clazz.
Compatibility behavior:
  • SDK 34 and above, this method matches platform behavior.
  • SDK 33 and below, the object type is checked after deserialization.
Link copied to clipboard
open fun <T> getSparseParcelableArray(@NonNull in: @NonNull Bundle, @Nullable key: @Nullable String, @NonNull clazz: @NonNull Class<out T>): @Nullable SparseArray<T>
Returns the value associated with the given key, or null if:
  • No mapping of the desired type exists for the given key.
  • A null value is explicitly associated with the key.
  • The object is not of type clazz.
Compatibility behavior:
  • SDK 34 and above, this method matches platform behavior.
  • SDK 33 and below, this method will not check the array elements' types.
Link copied to clipboard
open fun putBinder(@NonNull bundle: @NonNull Bundle, @Nullable key: @Nullable String, @Nullable binder: @Nullable IBinder)
A convenience method to handle putting an IBinder inside a Bundle for all Android versions.